export default {
	namespaced:true,
	state:()=>({
		city:'定位中...'
	}),
	mutations:{
		cityMut(state,city){
			state.city = city
		}
	},
	actions:{
		cityInitAct(context){
			// context  跟store一样的能力
			uni.getLocation({ //获取经纬度
				success: ({longitude,latitude}) => {
					console.log(longitude,latitude);
					uni.request({ //根据经纬度获取城市信息
						url:`https://restapi.amap.com/v3/geocode/regeo?key=d8b6435f9fc348bf711e1f8134e682c2&location=${longitude},${latitude}`,
						success: (res) => {
							console.log(res);
							let {province} = res.data.regeocode.addressComponent
							context.commit('cityMut',province)
						}
					})
				}
			})
		}
	}
}